<?php
namespace App\Common\Cla\EChat;

use App\Common as com;
use App\Common\Cla\EChat\JoinRoomPool as thisJoinRoomPool;
use App\Common\Cla\EChat as nameEChat;

class JoinRoomPool extends com\Cla\ClaBase {

	private com\Cla\EChat $eChat;

	/**
	 * @param com\Cla\EChat $eChat
	 */
	public function __construct( com\Cla\EChat $eChat) {
		$this->eChat = $eChat;
		//
		parent::__construct();
	}


	public function getEChat(  ):com\Cla\EChat {
		return $this->eChat;
	}

	/**
	 * 进入房间
	 * @param string|null $roomSid [null]随机创建
	 * @return Room
	 */
	public function joinRoom( ?string $roomSid = null ):nameEChat\Room {
		if( $roomSid === null ){
			$roomSid = nameEChat\Room::buildRandomRoomSid();
		}
		//
		return $this->goPoolParam( __FUNCTION__, $roomSid, function() use ( $roomSid ) {
			return $this->getEChat()->joinRoom( $roomSid );
		} );
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param com\Cla\EChat $eChat
	 * @return $this
	 */
	public static function makeOfNew( com\Cla\EChat $eChat ):self {
	    return self::make( $eChat );
	}

}
